﻿#ifndef _VECTOR_FEATURE_H_H_
#define _VECTOR_FEATURE_H_H_

#include "udatabase/dll_cfg.h"
#include "udatabase\interface\ifeature.h"
#include "graphicengine\OgreCommon.h"


namespace FD{
	namespace Utility{
		namespace DB{

class CVectorFeatureClass;
/// <summary>
/// 二维矢量要素类
/// </summary>
class FD_DB_Export CVectorFeature : public FD::Utility::DB::Interface::IFeature
{
	friend class CVectorFeatureClass;
	friend class CFeatureIterator;
public:
	/// <summary>
	/// 默认析构函数
	/// </summary>
	~CVectorFeature();
public:
	/// <summary>
	/// 获取要素ID
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回ID</returns>
	virtual uint32 getID() const;
	/// <summary>
	/// 获取要素几何体类型
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回要素几何体类型</returns>
	virtual FD::Kernel::Geometry::Interface::GeometryType getGeometryType() const;
	/// <summary>
	/// 获取要素字段信息
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回要素字段信息</returns>
	virtual const FD::Utility::DB::Interface::IFields* getFieldsRef() const;
	/// <summary>
	/// 获取要素字段数
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回要素字段数</returns>
	virtual uint32 getFieldCount() const;
	/// <summary>
	/// 通过索引获取字段
	/// </summary>
	/// <param name="index">第index个字段</param>
	/// <returns>返回字段</returns>
	virtual const FD::Utility::DB::Interface::IField* getFieldRef(uint32 index) const;
	/// <summary>
	/// 通过名称查找字段
	/// </summary>
	/// <param name="fieldName">字段名</param>
	/// <returns>返回字段索引</returns>
	virtual int32 findField(const String& fieldName) const;
	/// <summary>
	/// 通过索引获取字段值
	/// </summary>
	/// <param name="value">输出参数：字段值</param>
	/// <param name="index">索引处</param>
	/// <returns>返回字段值</returns>
	virtual void getValue(/*_out*/ FD::Kernel::Variant & value,uint32 index) const;
	/// <summary>
	/// 获取要素几何体
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回要素几何体</returns>
	virtual const FD::Kernel::Geometry::Interface::IGeometry * getGeometryRef() const;
	/// <summary>
	/// 获取要素几何体最小外接矩形
	/// </summary>
	/// <param name=""></param>
	/// <returns>返回要素几何体最小外接矩形</returns>
	virtual const FD::Kernel::Geometry::Interface::IEnvelope* getEnvelopeRef() const;
	/// <summary>
	/// 设置要素几何体
	/// </summary>
	/// <param name="geom">几何体</param>
	/// <returns></returns>
	virtual void setGeometry(const FD::Kernel::Geometry::Interface::IGeometry * geom);
	/// <summary>
	/// 设置字段值
	/// </summary>
	/// <param name="value">字段值</param>
	/// <param name="index">索引处</param>
	/// <returns></returns>
	virtual void setValue(const FD::Kernel::Variant & value,uint32 index);
	/// <summary>
	/// 删除要素
	/// </summary>
	/// <returns>若成功返回true；否则返回false</returns>
	virtual bool deleteFeature();
	/// <summary>
	/// 保存要素
	/// </summary>
	/// <returns>若成功返回true；否则返回false</returns>
	virtual bool saveFeature();
	/// <summary>
	/// 克隆要素
	/// </summary>
	/// <returns>返回克隆的要素，外部释放</returns>
	virtual   FD::Utility::DB::Interface::IFeature * clone() const;
private:
	//CVectorFeature(FD::GraphicEngine::NameValuePairList *pList);
protected:
	CVectorFeature();
	CVectorFeature(CVectorFeatureClass *pFC);

	void toStream(FD::Kernel::DataStream &stream);
	void initial();
	void solveAttributes();
	void attach( CVectorFeatureClass *fc, const FD::Utility::DB::Interface::IFields *fs );

protected:
	int32			m_pOID;

	const FD::Kernel::Geometry::Interface::IGeometry		*m_pGeometry;
	double			m_dfGeomLength;
	double			m_dfGeomArea;

	const FD::Utility::DB::Interface::IFields*		m_pFieldSet;

	/* 字段值映射 */
	vector<FD::Kernel::Variant> m_pValueVector;
	/* 统计那些字段需要更改 */ 
	vector<bool>	m_pDirtyVector;
	/* 是否破坏原有Geom数据 */
	bool				m_bDirty;

	bool					m_isBufferFeature;
	FD::Kernel::BufferDataStream		m_memBuffer;
	vector<size_t>	m_indicator;
	bool					m_isAttributesSolved;

	FD::Utility::DB::CVectorFeatureClass*	m_pSrcDataset;
};


}}} // End of namespaces

#endif //_VECTOR_FEATURE_H_H_

